package com.com.typhoon.service;

import com.com.typhoon.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.concurrent.Future;

/**
 * @author shuya | dongfeng.zdf@alibaba-inc.com
 * @description
 * @date 2018/10/22 下午2:01
 * @description
 * @modified by
 * @since V2.0.0
 */
@Service
@Slf4j
public class UserService {

    @Async
    public void createUserWithDefaultExecutor(){
        //SimpleAsyncTaskExecutor
        int a = 1/0;
        log.info("Currently Executing thread name - {}",Thread.currentThread().getName());
        log.info("User created with default executor");
    }

    @Async
    public Future<User> createAndReturnUser() {
        log.info("Currently Executing thread name - ",Thread.currentThread().getName());
        try {
            User user = new User();
            user.setName("Typhoon");
            user.setAge(28);
            user.setSex(1);
            int a = 1/0;
            Thread.sleep(5000);
            return new AsyncResult(user);
        } catch (InterruptedException e) {
            log.error(e.getMessage());
        }
        return null;
    }

}
